<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form-model ref="formRef">
        <div class="search-title">查询条件</div>
        <a-row>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="ykOrderNo"
                ><a-input v-model="queryParam.ykOrderNo" placeholder="英克采购订单号" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="createBy"
                ><a-input v-model="queryParam.createBy" placeholder="创建人" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="orderNo"
                ><a-input v-model="queryParam.orderNo" placeholder="订单号" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6">
          <div style="margin-right: 12px">
            <a-form-model-item prop="warehourse">
              <a-select
                showSearch
                v-model="queryParam.warehourse"
                style="width: 100%; margin-top: 4px"
                placeholder="请选择所属仓库"
                allowClear
              >
                <a-select-option v-for="(item, index) in warehouseOptions" :key="index" :value="item.value">
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </div>
        </a-col>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="supplyName"
                ><a-input v-model="queryParam.supplyName" placeholder="供应商名称" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="state">
                <a-select
                  v-model="queryParam.state"
                  style="width: 100%; margin-top: 4px"
                  placeholder="请选择订单状态"
                  allowClear
                >
                  <a-select-option v-for="(item, index) in saleOrderStates" :key="index" :value="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </div>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="8">
            <div style="margin-top: 4px">
              <a-button style="margin-right: 20px" @click="searchQuery()" type="primary"> 查询 </a-button>
              <a-upload
                name="file"
                :showUploadList="false"
                :multiple="false"
                :headers="tokenHeader"
                :action="importExcelUrl"
                @change="handleImportExcel"
                ><a-button type="primary" icon="import" style="margin-right: 20px">导入</a-button></a-upload
              >
              <a-button style="margin-right: 20px" @click="searchReset()"> 重置 </a-button>
            </div>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- 高级查询区域 -->
      <!-- <j-super-query
          :fieldList="superFieldList"
          ref="superQueryModal"
          @handleSuperQuery="handleSuperQuery"
        ></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>

        <template slot="detailAmount" slot-scope="text">
          {{ text.detailAmount ? text.detailAmount : '-' }}
        </template>

        <template slot="state" slot-scope="text">{{ getOrderState(text) }}</template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!--<a @click="handleEdit(record)">编辑</a>  -->
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleExport(record)">导出</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <YKPurchaseModal ref="modalForm" @ok="modalFormOk"></YKPurchaseModal>
  </a-card>
</template>

<script>
import { mapState, mapGetters } from 'vuex'
import { stateObjToArray } from '@/utils/common.js'

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import YKPurchaseModal from './modules/YKPurchaseModal'

export default {
  name: 'SaleOrderList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
      YKPurchaseModal,
  },
  data() {
    return {
      description: 'sale-order销售订单管理页面',
      // 表头
      columns: [
        {
          title: '英克采购订单号',
          align: 'center',
          dataIndex: 'ykOrderNo',
        },
        {
          title: '订单号',
          align: 'center',
          dataIndex: 'orderNo',
        },
        {
          title: '供应商名名称',
          align: 'center',
          dataIndex: 'supplyName',
        },
        {
          title: '细单数量',
          align: 'center',
        //   dataIndex: 'detailAmount',
          scopedSlots: { customRender: 'detailAmount' },
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '仓库名称',
          align: 'center',
          dataIndex: 'wareName',
        },
        {
          title: '状态',
          align: 'center',
          //dataIndex: 'state'
          scopedSlots: { customRender: 'state' },
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],

      url: {
        list: '/wms/wmsPurchaseOrder/list',
        delete: '/wms/wmsPurchaseOrder/delete',
        deleteBatch: '/wms/wmsPurchaseOrder/deleteBatch',
        exportXlsUrl: 'wms/wmsPurchaseOrder/exportXls',
        importExcelUrl: 'wms/wmsPurchaseOrder/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    ...mapGetters(['userInfo']),
    ...mapState({
      saleOrderTypes: (s) => {
        return stateObjToArray(s.order.saleOrderTypes)
      },
      inOrderStates: (s) => s.order.inOrderStates,
      saleOrderStates: (s) => {
        return stateObjToArray(s.order.saleOrderStates)
      },
      warehouseOptions: (s) => {
        return stateObjToArray(s.dictionary.enableWarehouse)
      },
      enableWarehouse: (s) => s.dictionary.enableWarehouse,
    }),
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    },
  },
  methods: {
    // dateChange(e) {
    //   console.log(e);
    //   this.queryParam.createTime = moment(e._d).format('YYYY-MM-DD')
    // },
 

    getOrderState(state) {
      if (state === '1') {
        return '已完成'
      } else if (state === '0') {
        return '已创建'
      } else {
        return '草稿'
      }
    },

    initDictConfig() {},
    handleExport(e) {
      // console.log('handleExport', e)
      this.handleExportXls('一品一码绑定_' + e.orderNo, { id: e.id, field: '' })
    },
    handleExport1(e) {
      this.handleExportXls('一品一码绑定')
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'orderNo', text: '订单号' })
      fieldList.push({ type: 'string', value: 'state', text: '状态' })
      fieldList.push({ type: 'int', value: 'sums', text: '数量' })
      fieldList.push({ type: 'int', value: 'createBy', text: '创建人' })
      fieldList.push({ type: 'string', value: 'createTime', text: '公司' })
      fieldList.push({ type: 'string', value: 'warehourse', text: '所属仓库' })
      this.superFieldList = fieldList
    },
    addOrder() {
      return this.$message.warning('功能暂未开放')
      this.$router.push({
        path: '/add-sale-order',
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.search-title {
  font-size: 16px;
  font-weight: 650;
  margin-bottom: 10px;
}
.ant-form-item {
  margin-bottom: 8px;
}
</style>
